#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author  : 陈伟


import jsonpath


class GetKeywords(object):

    @staticmethod
    def get_keyword(data, name):
        try:
            result = jsonpath.jsonpath(data, f'$..{name}')[0]
        except Exception as e:
            print(f"{name} 数据没有取到")
            return False
        return result

    @staticmethod
    def get_keyword_index(data, name, index:int):
        try:
            result = jsonpath.jsonpath(data, f'$..{name}')[index]
        except Exception as e:
            print(f"{name} 数据没有取到")
            return False
        return result

    @staticmethod
    def get_keywords(data, name):
        try:
            result = jsonpath.jsonpath(data, f'$..{name}')
        except Exception as e:
            print(f"{name} 数据没有取到")
            return False
        return result

